home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / edgetext / clsdate_.cl_ / clsdate_.cl
Encoding:
Text File  |  1998-03-21  |  52.9 KB  |  1,420 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. End
  5. Attribute VB_Name = "clsDate_range"
  6. Attribute VB_Creatable = True
  7. Attribute VB_PredeclaredId = False
  8. Attribute VB_Exposed = False
  9. Option Explicit
  10. '**************************************************************************************
  11. 'Title:     clsDate_range.cls 
  12. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  13. 'Purpose:   This class allows single record access to the Date_range Table 
  14. 'Properties:Equate to the fields in the table
  15. 'Methods:   Allow for record manipulation
  16.  
  17.  
  18. 'It is recommended that the Database object Dbtimesheet be declared global
  19.  
  20. 'It is also recommended that the Configuration object be declared global if it is being used
  21. 'This is so that it can be persistent
  22. '**************************************************************************************
  23.  
  24. 'Here are the Field Properties for this table Class
  25. Public Date_Id as Long
  26. Public Starting_Date as String
  27. Public Ending_Date as String
  28. Public Updated_By as String
  29. Public Update_Module as String
  30. Public Update_Time as String
  31.  
  32. 'These are the ScratchPad Variables
  33. Private mDate_Id as Long
  34. Private mStarting_Date as String
  35. Private mEnding_Date as String
  36. Private mUpdated_By as String
  37. Private mUpdate_Module as String
  38. Private mUpdate_Time as String
  39.  
  40. 'This public variable tells whether a function was successful, it is True when a function
  41. 'is successful, and false when a function is unsuccessful
  42. Public Success as Boolean
  43. 'This is the Error Code which was generated in the function call, it matches Err from VB
  44. Public ErrorCode as Double
  45. 'This is the Error message which was generated in the function call, it matches Errors(0) VB
  46. Public ErrorMessage as String
  47. 'This Constant tells the error traps how many retries to perform
  48. Private Const MaxRetries = 4
  49.  
  50. '********************************************************************************************************
  51. 'Title:     CreateTable
  52. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  53. 'Purpose:   This subroutine Creates the very table that this class was created to read and write    
  54. 'Parameters:None
  55. 'Return:    Nothing
  56. '********************************************************************************************************
  57. Public Sub CreateTable()
  58.  
  59. Dim lsCreate as string
  60. Dim RetCode as integer, liCount as integer, BadCount as integer
  61.  
  62.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  63.     Success = True
  64.     'The ErrorCode is the Err returned by VB for the Trapped Error
  65.     ErrorCode = False
  66.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  67.     If Not objConfiguration.DebugFlag Then
  68.         On Error GoTo NoDate_rangeCreateTable
  69.     End If
  70.  
  71.  
  72.     'Assemble the SQL String
  73.     lsCreate = "Create Table DATE_RANGE ("
  74.     lsCreate = lsCreate & "Date_Id Long(4),"
  75.     lsCreate = lsCreate & "Starting_Date Date/Time(8),"
  76.     lsCreate = lsCreate & "Ending_Date Date/Time(8),"
  77.     lsCreate = lsCreate & "Updated_By String(50),"
  78.     lsCreate = lsCreate & "Update_Module String(50),"
  79.     lsCreate = lsCreate & "Update_Time Date/Time(8))"
  80.  
  81.     'Execute the SQL
  82.     Dbtimesheet.Execute lsCreate
  83.     On Error GoTo 0
  84.     Exit Sub
  85.  
  86. NoDate_rangeCreateTable:
  87.  
  88.     'Retry for a predermined number of times, set by the MaxRetries Constant
  89.     If BadCount < MaxRetries Then
  90.         'if we have been exceeded retries on a previous error in this routine,
  91.         'just give the remaining errors one try, and don't save these errors,
  92.         'the interest should be in the original error
  93.         If Success = False Then
  94.             Resume Next
  95.         Else
  96.             'increment the retry counter
  97.             BadCount = BadCount + 1
  98.             'Look for Database errors and see if you can fix the error by reconnecting
  99.             If Err = 3146 or Err = 3075 then
  100.                 'Try Reconnecting to the database, then
  101.                 'keep executing the same line of code in a hope that retries will
  102.                 'be the solution to the problem.
  103.                 On Error GoTo BadDate_rangeCreateTableConnect
  104.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  105.                 On Error goto 0
  106.             End If
  107.             Resume 0
  108.         End If
  109.     Else
  110.         'At MaxRetries, flag a failure in the routine
  111.         Success = False
  112.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  113.         'get a reason why the error occurred
  114.         ErrorCode = Err
  115.         objError.ErrorCode = Err
  116.         objError.FunctionName = "clsDate_range.CreateTable"
  117.         If Err = 3146 then
  118.             objError.Message = "Date_range, CreateTable " & vbcrlf & Errors(0) & " "
  119.             ErrorMessage = Errors(0)
  120.         Else
  121.             objError.Message = "Date_range, CreateTable "
  122.             ErrorMessage = Error(Err)
  123.         End If
  124.         objError.SQL = lsCreate
  125.         objError.Display vbExclamation
  126.         'reset the counter
  127.         BadCount = 0
  128.         'and try to execute the next line of code in the routine
  129.         Resume Next
  130.     End If
  131.  
  132. BadDate_rangeCreateTableConnect:
  133.     'You can put additional database reopening error checking here if necessary
  134.     Resume Next
  135.  
  136.  
  137. End Sub
  138.  
  139.  
  140. '********************************************************************************************************
  141. 'Title:     AddItem
  142. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  143. 'Purpose:   This method Adds Items to the Database after the Key properties
  144. '           of the class have been filled
  145. 'Parameters:None
  146. 'Return:    Nothing
  147. '********************************************************************************************************
  148. Public Sub AddItem()
  149.  
  150. Dim lsAdd as string
  151. Dim RetCode as integer, liCount as integer, BadCount as integer
  152.  
  153.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  154.     Success = True
  155.     'The ErrorCode is the Err returned by VB for the Trapped Error
  156.     ErrorCode = False
  157.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  158.     If Not objConfiguration.DebugFlag Then
  159.         On Error GoTo NoDate_rangeAddItem
  160.     End If
  161.  
  162.     'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  163.     StoreProperties
  164.     SetDefaultDates
  165.  
  166.     'Now Pad fields with a space if the record cannot be added with zero length
  167.     PadFields
  168.  
  169.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  170.     DoubleYourQuotes
  171.  
  172.     'Assemble the SQL String
  173.     lsAdd = "Insert into DATE_RANGE ("
  174.     'First the Field List
  175.     lsAdd = lsAdd & "Date_Id,"
  176.     lsAdd = lsAdd & "Starting_Date,"
  177.     lsAdd = lsAdd & "Ending_Date,"
  178.     lsAdd = lsAdd & "Updated_By,"
  179.     lsAdd = lsAdd & "Update_Module,"
  180.     lsAdd = lsAdd & "Update_Time)"
  181.     lsAdd = lsAdd & " Values("
  182.     'Now the Value List
  183.     lsAdd = lsAdd & "" & Format(Date_Id) & ","
  184.     lsAdd = lsAdd & "" & Starting_Date & ","
  185.     lsAdd = lsAdd & "" & Ending_Date & ","
  186.     'These are the Audit Trail Fields
  187.     lsAdd = lsAdd & "'" & objConfiguration.LanId & "',"
  188.     lsAdd = lsAdd & "'" & objConfiguration.ModuleName & "',"
  189.     lsAdd = lsAdd & "#" & format(Now,"MM/DD/YYYY hh:mm:ss") & "#)"
  190.  
  191.     'Execute the SQL
  192.     Dbtimesheet.Execute lsAdd
  193.  
  194.     'Reassign the original values to the properties list
  195.     RetrieveProperties
  196.  
  197.     On Error GoTo 0
  198.     Exit Sub
  199.  
  200. NoDate_rangeAddItem:
  201.  
  202.     'Retry for a predermined number of times, set by the MaxRetries Constant
  203.     If BadCount < MaxRetries Then
  204.         'if we have been exceeded retries on a previous error in this routine,
  205.         'just give the remaining errors one try, and don't save these errors,
  206.         'the interest should be in the original error
  207.         If Success = False Then
  208.             Resume Next
  209.         Else
  210.             'increment the retry counter
  211.             BadCount = BadCount + 1
  212.             'Look for Database errors and see if you can fix the error by reconnecting
  213.             If Err = 3146 or Err = 3075 then
  214.                 'Try Reconnecting to the database, then
  215.                 'keep executing the same line of code in a hope that retries will
  216.                 'be the solution to the problem.
  217.                 On Error GoTo BadDate_rangeAddItemConnect
  218.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  219.                 On Error goto 0
  220.             End If
  221.             Resume 0
  222.         End If
  223.     Else
  224.         'At MaxRetries, flag a failure in the routine
  225.         Success = False
  226.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  227.         'get a reason why the error occurred
  228.         ErrorCode = Err
  229.         objError.ErrorCode = Err
  230.         objError.FunctionName = "clsDate_range.AddItem"
  231.         If Err = 3146 then
  232.             objError.Message = "Date_range, AddItem " & vbcrlf & Errors(0) & " "
  233.             ErrorMessage = Errors(0)
  234.         Else
  235.             objError.Message = "Date_range, AddItem "
  236.             ErrorMessage = Error(Err)
  237.         End If
  238.         objError.SQL = lsAdd
  239.         objError.Display vbExclamation
  240.         'reset the counter
  241.         BadCount = 0
  242.         'and try to execute the next line of code in the routine
  243.         Resume Next
  244.     End If
  245.  
  246. BadDate_rangeAddItemConnect:
  247.     'You can put additional database reopening error checking here if necessary
  248.     Resume Next
  249.  
  250.  
  251. End Sub
  252.  
  253. '********************************************************************************************************
  254. 'Title:     ClearValues
  255. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  256. 'Purpose:   This method clears all fields in the Table class
  257. 'Parameters:None
  258. 'Return:    Nothing
  259. '********************************************************************************************************
  260. Sub ClearValues()
  261.  
  262.     Date_Id = 0
  263.     Starting_Date = ""
  264.     Ending_Date = ""
  265.     Updated_By = ""
  266.     Update_Module = ""
  267.     Update_Time = ""
  268.  
  269. End Sub
  270.  
  271.  
  272. '********************************************************************************************************
  273. 'Title:     DeleteItem
  274. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  275. 'Purpose:   This method Deletes Items from the Database after the Key fields have been filled
  276. 'Parameters:None
  277. 'Return:    Nothing
  278. '********************************************************************************************************
  279. Public Sub DeleteItem()
  280.  
  281. Dim lrsDate_range as RecordSet, lsDelete as string
  282. Dim RetCode as integer,lsCount as integer,liCount as integer,BadCount as integer
  283.  
  284.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  285.     Success = True
  286.     'The ErrorCode is the Err returned by VB for the Trapped Error
  287.     ErrorCode = False
  288.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  289.     If Not objConfiguration.DebugFlag Then
  290.         On Error GoTo NoDate_rangeDeleteItem
  291.     End If
  292.  
  293.     'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  294.     StoreProperties
  295.     SetDefaultDates
  296.  
  297.     'Now Pad fields with a space if the record cannot be added with zero length
  298.     PadFields
  299.  
  300.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  301.     DoubleYourQuotes
  302.  
  303.     'Assemble the SQL String
  304.     lsDelete = "Delete from DATE_RANGE  where Date_Id = " & Format(Date_Id) & ""
  305.  
  306.     'Execute the SQL
  307.      Dbtimesheet.Execute lsDelete
  308.  
  309.     'Now ReAssign the Temp vars back to the class props
  310.     RetrieveProperties
  311.  
  312.     On Error GoTo 0
  313.     Exit Sub
  314.  
  315. NoDate_rangeDeleteItem:
  316.  
  317.     'Retry for a predermined number of times, set by the MaxRetries Constant
  318.     If BadCount < MaxRetries Then
  319.         'if we have been exceeded retries on a previous error in this routine,
  320.         'just give the remaining errors one try, and don't save these errors,
  321.         'the interest should be in the original error
  322.         If Success = False Then
  323.             Resume Next
  324.         Else
  325.             'increment the retry counter
  326.             BadCount = BadCount + 1
  327.             'Look for Database errors and see if you can fix the error by reconnecting
  328.             If Err = 3146 or Err = 3075 then
  329.                 'Try Reconnecting to the database, then
  330.                 'keep executing the same line of code in a hope that retries will
  331.                 'be the solution to the problem.
  332.                 On Error GoTo BadDate_rangeDeleteItemConnect
  333.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  334.                 On Error goto 0
  335.             End If
  336.             Resume 0
  337.         End If
  338.     Else
  339.         'At MaxRetries, flag a failure in the routine
  340.         Success = False
  341.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  342.         'get a reason why the error occurred
  343.         ErrorCode = Err
  344.         objError.ErrorCode = Err
  345.         objError.FunctionName = "clsDate_range.DeleteItem"
  346.         If Err = 3146 then
  347.             objError.Message = "Date_range, DeleteItem " & vbcrlf & Errors(0) & " "
  348.             ErrorMessage = Errors(0)
  349.         Else
  350.             objError.Message = "Date_range, DeleteItem "
  351.             ErrorMessage = Error(Err)
  352.         End If
  353.         objError.SQL = lsDelete
  354.         objError.Display vbExclamation
  355.         'reset the counter
  356.         BadCount = 0
  357.         'and try to execute the next line of code in the routine
  358.         Resume Next
  359.     End If
  360.  
  361. BadDate_rangeDeleteItemConnect:
  362.     'You can put additional database reopening error checking here if necessary
  363.     Resume Next
  364.  
  365.  
  366. End Sub
  367.  
  368.  
  369. '********************************************************************************************************
  370. 'Title:     FillObjectFromRecordset
  371. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  372. 'Purpose    This sub fills all the properties of the class from a given recordset
  373. 'Parameters:The recordset from which to fill
  374. 'Return:    Nothing
  375. '********************************************************************************************************
  376. Public Sub FillObjectFromRecordSet(lrsDate_range as RecordSet)
  377.  
  378. Dim liCount as Integer, BadCount as Integer, pSQL as String, lsSelect as String
  379.     If Not objConfiguration.DebugFlag Then
  380.         On Error GoTo NoDate_rangeFillObject
  381.     End If
  382.  
  383.     'Appending a & "" onto the end of a recordset field checks for Null values
  384.     'Similarly, Numbers are explicitly converted to eliminate Null values as well
  385.     Date_Id = Val(lrsDate_range![Date_Id] & "")
  386.     Starting_Date = lrsDate_range![Starting_Date] & ""
  387.     Ending_Date = lrsDate_range![Ending_Date] & ""
  388.     Updated_By = lrsDate_range![Updated_By] & ""
  389.     Update_Module = lrsDate_range![Update_Module] & ""
  390.     Update_Time = lrsDate_range![Update_Time] & ""
  391.     On Error GoTo 0
  392.     Exit Sub
  393.  
  394. NoDate_rangeFillObject:
  395.  
  396.     'Retry for a predermined number of times, set by the MaxRetries Constant
  397.     If BadCount < MaxRetries Then
  398.         'if we have been exceeded retries on a previous error in this routine,
  399.         'just give the remaining errors one try, and don't save these errors,
  400.         'the interest should be in the original error
  401.         If Success = False Then
  402.             Resume Next
  403.         Else
  404.             'increment the retry counter
  405.             BadCount = BadCount + 1
  406.             'Look for Database errors and see if you can fix the error by reconnecting
  407.             If Err = 3146 or Err = 3075 then
  408.                 'Try Reconnecting to the database, then
  409.                 'keep executing the same line of code in a hope that retries will
  410.                 'be the solution to the problem.
  411.                 On Error GoTo BadDate_rangeFillObjectConnect
  412.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  413.                 On Error goto 0
  414.             End If
  415.             Resume 0
  416.         End If
  417.     Else
  418.         'At MaxRetries, flag a failure in the routine
  419.         Success = False
  420.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  421.         'get a reason why the error occurred
  422.         ErrorCode = Err
  423.         objError.ErrorCode = Err
  424.         objError.FunctionName = "clsDate_range.FillObject"
  425.         If Err = 3146 then
  426.             objError.Message = "Date_range, FillObject " & vbcrlf & Errors(0) & " "
  427.             ErrorMessage = Errors(0)
  428.         Else
  429.             objError.Message = "Date_range, FillObject "
  430.             ErrorMessage = Error(Err)
  431.         End If
  432.         objError.SQL = lsSelect
  433.         objError.Display vbExclamation
  434.         'reset the counter
  435.         BadCount = 0
  436.         'and try to execute the next line of code in the routine
  437.         Resume Next
  438.     End If
  439.  
  440. BadDate_rangeFillObjectConnect:
  441.     'You can put additional database reopening error checking here if necessary
  442.     Resume Next
  443.  
  444.  
  445. End Sub
  446.  
  447.  
  448. '********************************************************************************************************
  449. 'Title:     GetItem
  450. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  451. 'Purpose:   This Method Gets a record from the database after the Key Fields have been Filled
  452. 'Parameters:The recordset from which to fill
  453. 'Return:    Nothing
  454. '********************************************************************************************************
  455. Public Sub GetItem()
  456.  
  457. Dim lrsGetItem as RecordSet, lsSelect as string
  458. Dim RetCode as integer,lsCount as integer,liCount as integer,BadCount as integer
  459.  
  460.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  461.     Success = True
  462.     'The ErrorCode is the Err returned by VB for the Trapped Error
  463.     ErrorCode = False
  464.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  465.     If Not objConfiguration.DebugFlag Then
  466.         On Error GoTo NoDate_rangeGetItem
  467.     End If
  468.  
  469.     'First we assign all the properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  470.     StoreProperties
  471.     SetDefaultDates
  472.  
  473.     'Now Pad fields with a space if the record cannot be added with zero length
  474.     PadFields
  475.  
  476.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  477.     DoubleYourQuotes
  478.  
  479.     'Assemble the SQL String
  480.     lsSelect = "Select * from DATE_RANGE  where Date_Id = " & Format(Date_Id) & ""
  481.  
  482.     'Execute the SQL
  483.      Set lrsGetItem = Dbtimesheet.OpenRecordSet(lsSelect)
  484.  
  485.     'Now ReAssign the Temp vars back to the class props
  486.     RetrieveProperties
  487.  
  488.     'Check for a valid record
  489.     If Not Success Then
  490.         Exit Sub
  491.     End If
  492.     If lrsGetItem.RecordCount = 0 Then
  493.         Success = False
  494.         Exit Sub
  495.     End If
  496.  
  497.     'Fill the Table Class Fields from the Recordset
  498.     FillObjectFromRecordset lrsGetItem
  499.     'Check for Errors    
  500.     if not Success then
  501.         Exit sub
  502.     end if
  503.     lrsGetItem.Close
  504.  
  505.     'Now trim the spaces out of the padded fields
  506.     TrimPaddedFields
  507.  
  508.     'Strip the NULLs or bad dates out of date fields
  509.     StripDates False
  510.  
  511.     On Error GoTo 0
  512.     Exit Sub
  513.  
  514. NoDate_rangeGetItem:
  515.  
  516.     'Retry for a predermined number of times, set by the MaxRetries Constant
  517.     If BadCount < MaxRetries Then
  518.         'if we have been exceeded retries on a previous error in this routine,
  519.         'just give the remaining errors one try, and don't save these errors,
  520.         'the interest should be in the original error
  521.         If Success = False Then
  522.             Resume Next
  523.         Else
  524.             'increment the retry counter
  525.             BadCount = BadCount + 1
  526.             'Look for Database errors and see if you can fix the error by reconnecting
  527.             If Err = 3146 or Err = 3075 then
  528.                 'Try Reconnecting to the database, then
  529.                 'keep executing the same line of code in a hope that retries will
  530.                 'be the solution to the problem.
  531.                 On Error GoTo BadDate_rangeGetItemConnect
  532.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  533.                 On Error goto 0
  534.             End If
  535.             Resume 0
  536.         End If
  537.     Else
  538.         'At MaxRetries, flag a failure in the routine
  539.         Success = False
  540.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  541.         'get a reason why the error occurred
  542.         ErrorCode = Err
  543.         objError.ErrorCode = Err
  544.         objError.FunctionName = "clsDate_range.GetItem"
  545.         If Err = 3146 then
  546.             objError.Message = "Date_range, GetItem " & vbcrlf & Errors(0) & " "
  547.             ErrorMessage = Errors(0)
  548.         Else
  549.             objError.Message = "Date_range, GetItem "
  550.             ErrorMessage = Error(Err)
  551.         End If
  552.         objError.SQL = lsSelect
  553.         objError.Display vbExclamation
  554.         'reset the counter
  555.         BadCount = 0
  556.         'and try to execute the next line of code in the routine
  557.         Resume Next
  558.     End If
  559.  
  560. BadDate_rangeGetItemConnect:
  561.     'You can put additional database reopening error checking here if necessary
  562.     Resume Next
  563.  
  564.  
  565. End Sub
  566.  
  567.  
  568. '********************************************************************************************************
  569. 'Title:     GetNewId
  570. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  571. 'Purpose:   This Method Gets a new Id using the Max function in SQL, it has only limited value, but is included as
  572. '           a template for new Primary Key generation
  573. 'Parameters:None
  574. 'Return:    Nothing
  575. '********************************************************************************************************
  576. Public function GetNewId() as double
  577.  
  578. Dim lrsGetNewId as RecordSet, lsSelect as string
  579. Dim RetCode as integer,liCount as integer,BadCount as integer
  580.  
  581.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  582.     Success = True
  583.     'The ErrorCode is the Err returned by VB for the Trapped Error
  584.     ErrorCode = False
  585.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  586.     If Not objConfiguration.DebugFlag Then
  587.         On Error GoTo NoDate_rangeGetNewId
  588.     End If
  589.  
  590.     'First we assign all the date and text properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  591.     StoreProperties
  592.     SetDefaultDates
  593.  
  594.     'Now Pad fields with a space if the record cannot be added with zero length
  595.     PadFields
  596.  
  597.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  598.     DoubleYourQuotes
  599.  
  600.  
  601.     'The SQL provided here is just a simple Get Max.  This would only be useful for very small tables
  602.     'If you anticipate this table growing past a few hundred rows, change this routine accordingly
  603.     'You might try keeping a table with the last Id stored as a field, which can then be updated when a 
  604.     'new Id is required.
  605.  
  606.     'Assemble the SQL String
  607.     lsSelect = "Select Max(Date_Id) from DATE_RANGE 
  608.  
  609.     'Execute the SQL
  610.     Set lrsGetNewId = Dbtimesheet.OpenRecordSet(lsSelect)
  611.  
  612.     'Now ReAssign the Temp vars back to the class props
  613.     RetrieveProperties
  614.  
  615.     'Don't forget to check for those NULLS
  616.     If Not IsNull(lrsGetNewId(0)) Then
  617.         GetNewId = lrsGetNewId(0) + 1
  618.     Else
  619.         GetNewId = 1
  620.     End If
  621.     lrsGetNewId.Close
  622.     On Error GoTo 0
  623.     Exit Function
  624.  
  625. NoDate_rangeGetNewId:
  626.  
  627.     'Retry for a predermined number of times, set by the MaxRetries Constant
  628.     If BadCount < MaxRetries Then
  629.         'if we have been exceeded retries on a previous error in this routine,
  630.         'just give the remaining errors one try, and don't save these errors,
  631.         'the interest should be in the original error
  632.         If Success = False Then
  633.             Resume Next
  634.         Else
  635.             'increment the retry counter
  636.             BadCount = BadCount + 1
  637.             'Look for Database errors and see if you can fix the error by reconnecting
  638.             If Err = 3146 or Err = 3075 then
  639.                 'Try Reconnecting to the database, then
  640.                 'keep executing the same line of code in a hope that retries will
  641.                 'be the solution to the problem.
  642.                 On Error GoTo BadDate_rangeGetNewIdConnect
  643.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  644.                 On Error goto 0
  645.             End If
  646.             Resume 0
  647.         End If
  648.     Else
  649.         'At MaxRetries, flag a failure in the routine
  650.         Success = False
  651.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  652.         'get a reason why the error occurred
  653.         ErrorCode = Err
  654.         objError.ErrorCode = Err
  655.         objError.FunctionName = "clsDate_range.GetNewId"
  656.         If Err = 3146 then
  657.             objError.Message = "Date_range, GetNewId " & vbcrlf & Errors(0) & " "
  658.             ErrorMessage = Errors(0)
  659.         Else
  660.             objError.Message = "Date_range, GetNewId "
  661.             ErrorMessage = Error(Err)
  662.         End If
  663.         objError.SQL = lsSelect
  664.         objError.Display vbExclamation
  665.         'reset the counter
  666.         BadCount = 0
  667.         'and try to execute the next line of code in the routine
  668.         Resume Next
  669.     End If
  670.  
  671. BadDate_rangeGetNewIdConnect:
  672.     'You can put additional database reopening error checking here if necessary
  673.     Resume Next
  674.  
  675.  
  676. End Function
  677.  
  678.  
  679. '********************************************************************************************************
  680. 'Title:     ParseItem
  681. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  682. 'Purpose:   This method can parse fields which have values in them.  It will create an SQL criteria string
  683. '           using like statements for strings, and = statements for numbers and dates, this can be used
  684. '           in Query by Example screens with little or no modification
  685. 'Parameters:None
  686. 'Return:    The Parsed String for use in SQL
  687. '********************************************************************************************************
  688. Public Function ParseItem(piAndFlag as Integer) As String
  689.  
  690. Dim RetCode as integer,liCount as integer,Buf1 as String
  691. Dim BadCount as integer, WildCard As String
  692.  
  693.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  694.     Success = True
  695.     'The ErrorCode is the Err returned by VB for the Trapped Error
  696.     ErrorCode = False
  697.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  698.     If Not objConfiguration.DebugFlag Then
  699.         On Error GoTo NoDate_rangeParseItem
  700.     End If
  701.  
  702.     'Change this based on your database, MS-Access uses the *, but SQL standard is the %
  703.     wildcard = "*'"
  704.     
  705.     'First we assign all the date and text properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  706.     StoreProperties
  707.     SetDefaultDates
  708.  
  709.     'Now Pad fields with a space if the record cannot be added with zero length
  710.     PadFields
  711.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  712.     DoubleYourQuotes
  713.  
  714.  
  715.     If Date_Id <> 0 Then
  716.         If piAndFlag Then
  717.             Buf1 = Buf1 & " And "
  718.         Else
  719.             Buf1 = Buf1 & " Where "
  720.         End If
  721.         Buf1 = Buf1 & "Date_range.Date_Id = " & Format(Date_Id)
  722.         piAndFlag = True
  723.     End If
  724.  
  725.     if isDate(Starting_Date) then
  726.         If piAndFlag Then
  727.             Buf1 = Buf1 & " And "
  728.         Else
  729.             Buf1 = Buf1 & " Where "
  730.         End If
  731.         Buf1 = Buf1 & "Date_range.Starting_Date = " & Starting_Date
  732.         piAndFlag = True
  733.     End If
  734.  
  735.     if isDate(Ending_Date) then
  736.         If piAndFlag Then
  737.             Buf1 = Buf1 & " And "
  738.         Else
  739.             Buf1 = Buf1 & " Where "
  740.         End If
  741.         Buf1 = Buf1 & "Date_range.Ending_Date = " & Ending_Date
  742.         piAndFlag = True
  743.     End If
  744.  
  745.     If Trim(Updated_By) <> "" Then
  746.         If piAndFlag Then
  747.             Buf1 = Buf1 & " And "
  748.         Else
  749.             Buf1 = Buf1 & " Where "
  750.         End If
  751.         Buf1 = Buf1 & "Date_range.Updated_By like '" & Trim(Updated_By) & WildCard
  752.         piAndFlag = True
  753.     End If
  754.  
  755.     If Trim(Update_Module) <> "" Then
  756.         If piAndFlag Then
  757.             Buf1 = Buf1 & " And "
  758.         Else
  759.             Buf1 = Buf1 & " Where "
  760.         End If
  761.         Buf1 = Buf1 & "Date_range.Update_Module like '" & Trim(Update_Module) & WildCard
  762.         piAndFlag = True
  763.     End If
  764.  
  765.     if isDate(Update_Time) then
  766.         If piAndFlag Then
  767.             Buf1 = Buf1 & " And "
  768.         Else
  769.             Buf1 = Buf1 & " Where "
  770.         End If
  771.         Buf1 = Buf1 & "Date_range.Update_Time = " & Update_Time
  772.         piAndFlag = True
  773.     End If
  774.  
  775.     'now reassign the temp values back to the properties
  776.     RetrieveProperties
  777.  
  778.     On Error GoTo 0
  779.     ParseItem = Buf1
  780.     Exit Function
  781.  
  782. NoDate_rangeParseItem:
  783.  
  784.     'Retry for a predermined number of times, set by the MaxRetries Constant
  785.     If BadCount < MaxRetries Then
  786.         'if we have been exceeded retries on a previous error in this routine,
  787.         'just give the remaining errors one try, and don't save these errors,
  788.         'the interest should be in the original error
  789.         If Success = False Then
  790.             Resume Next
  791.         Else
  792.             'increment the retry counter
  793.             BadCount = BadCount + 1
  794.             'Look for Database errors and see if you can fix the error by reconnecting
  795.             If Err = 3146 or Err = 3075 then
  796.                 'Try Reconnecting to the database, then
  797.                 'keep executing the same line of code in a hope that retries will
  798.                 'be the solution to the problem.
  799.                 On Error GoTo BadDate_rangeParseItemConnect
  800.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  801.                 On Error goto 0
  802.             End If
  803.             Resume 0
  804.         End If
  805.     Else
  806.         'At MaxRetries, flag a failure in the routine
  807.         Success = False
  808.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  809.         'get a reason why the error occurred
  810.         ErrorCode = Err
  811.         objError.ErrorCode = Err
  812.         objError.FunctionName = "clsDate_range.ParseItem"
  813.         If Err = 3146 then
  814.             objError.Message = "Date_range, ParseItem " & vbcrlf & Errors(0) & " "
  815.             ErrorMessage = Errors(0)
  816.         Else
  817.             objError.Message = "Date_range, ParseItem "
  818.             ErrorMessage = Error(Err)
  819.         End If
  820.         objError.SQL = Buf1
  821.         objError.Display vbExclamation
  822.         'reset the counter
  823.         BadCount = 0
  824.         'and try to execute the next line of code in the routine
  825.         Resume Next
  826.     End If
  827.  
  828. BadDate_rangeParseItemConnect:
  829.     'You can put additional database reopening error checking here if necessary
  830.     Resume Next
  831.  
  832.  
  833. End Function
  834.  
  835.  
  836. '********************************************************************************************************
  837. 'Title:     UpdateItem
  838. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  839. 'Purpose:   This method updates a record in the database using the primary key, it is recommended that you
  840. '           Fill the Key Fields, use the get method, fill the fields which have changed, 
  841. '           then call this method to perform the update
  842. 'Parameters:None
  843. 'Return:    Nothing
  844. '********************************************************************************************************
  845. Public Sub UpdateItem()
  846.  
  847. Dim lsUpdate as string
  848. Dim RetCode as integer, liCount as integer, BadCount as integer
  849.  
  850.     'The Success flag gets initialized to True and set to false if a trappable error occurs
  851.     Success = True
  852.     'The ErrorCode is the Err returned by VB for the Trapped Error
  853.     ErrorCode = False
  854.     'The DebugFlag is the provision which turns off all error checking in the table class when false
  855.     If Not objConfiguration.DebugFlag Then
  856.         On Error GoTo NoDate_rangeUpdateItem
  857.     End If
  858.  
  859.     'First we will assign the date properties to temp vars and set any blank dates to NULL, or put in the date delimiters (Database Dependent)
  860.     StoreProperties
  861.     SetDefaultDates
  862.  
  863.     'Now Pad fields with a space if the record cannot be added with zero length
  864.     PadFields
  865.  
  866.     'The Double Your Quotes routine doubles any single quotes in string type variables for SQL compatibility
  867.     DoubleYourQuotes
  868.  
  869.     'Assemble the SQL String
  870.     lsUpdate = "Update DATE_RANGE Set "
  871.     lsUpdate = lsUpdate & "Starting_Date = " & Starting_Date & ","
  872.     lsUpdate = lsUpdate & "Ending_Date = " & Ending_Date & ","
  873.     'These are the Audit Trail Fields
  874.     lsUpdate = lsUpdate & "Updated_By = '" & objConfiguration.LanId & "',"
  875.     lsUpdate = lsUpdate & "Update_Module = '" & objConfiguration.ModuleName & "',"
  876.     lsUpdate = lsUpdate & "Update_Time = #" & format(Now,"MM/DD/YYYY hh:mm:ss") & "# "
  877.     lsUpdate = lsUpdate & " where Date_Id = " & Format(Date_Id) & ""
  878.  
  879.     'Execute the SQL
  880.     Dbtimesheet.Execute lsUpdate
  881.  
  882.     'now reassign the temp values back to the properties
  883.     RetrieveProperties
  884.  
  885.     On Error GoTo 0
  886.     Exit Sub
  887.  
  888. NoDate_rangeUpdateItem:
  889.  
  890.     'Retry for a predermined number of times, set by the MaxRetries Constant
  891.     If BadCount < MaxRetries Then
  892.         'if we have been exceeded retries on a previous error in this routine,
  893.         'just give the remaining errors one try, and don't save these errors,
  894.         'the interest should be in the original error
  895.         If Success = False Then
  896.             Resume Next
  897.         Else
  898.             'increment the retry counter
  899.             BadCount = BadCount + 1
  900.             'Look for Database errors and see if you can fix the error by reconnecting
  901.             If Err = 3146 or Err = 3075 then
  902.                 'Try Reconnecting to the database, then
  903.                 'keep executing the same line of code in a hope that retries will
  904.                 'be the solution to the problem.
  905.                 On Error GoTo BadDate_rangeUpdateItemConnect
  906.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  907.                 On Error goto 0
  908.             End If
  909.             Resume 0
  910.         End If
  911.     Else
  912.         'At MaxRetries, flag a failure in the routine
  913.         Success = False
  914.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  915.         'get a reason why the error occurred
  916.         ErrorCode = Err
  917.         objError.ErrorCode = Err
  918.         objError.FunctionName = "clsDate_range.UpdateItem"
  919.         If Err = 3146 then
  920.             objError.Message = "Date_range, UpdateItem " & vbcrlf & Errors(0) & " "
  921.             ErrorMessage = Errors(0)
  922.         Else
  923.             objError.Message = "Date_range, UpdateItem "
  924.             ErrorMessage = Error(Err)
  925.         End If
  926.         objError.SQL = lsUpdate
  927.         objError.Display vbExclamation
  928.         'reset the counter
  929.         BadCount = 0
  930.         'and try to execute the next line of code in the routine
  931.         Resume Next
  932.     End If
  933.  
  934. BadDate_rangeUpdateItemConnect:
  935.     'You can put additional database reopening error checking here if necessary
  936.     Resume Next
  937.  
  938.  
  939. End Sub
  940.  
  941. '********************************************************************************************************
  942. 'Title:     DoubleYourQuotes
  943. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  944. 'Purpose:   This routine Doubles your Single Quotes in all string or memo 
  945. '           fields in the class for SQL compatibility
  946. 'Parameters:None
  947. 'Return:    Nothing
  948. '********************************************************************************************************
  949. Private Sub DoubleYourQuotes()
  950.  
  951. Dim liCount as integer,BadCount as integer
  952.  
  953.     If Not objConfiguration.DebugFlag Then
  954.         On Error GoTo NoDate_rangeDoubleYourQuotes
  955.     End If
  956.  
  957.     'These lines double the single quotes in any string field in the class
  958.     Updated_By = SearchandDouble(Updated_By)
  959.     Update_Module = SearchandDouble(Update_Module)
  960.     On Error GoTo 0
  961.     Exit Sub
  962.  
  963. NoDate_rangeDoubleYourQuotes:
  964.  
  965.     'Retry for a predermined number of times, set by the MaxRetries Constant
  966.     If BadCount < MaxRetries Then
  967.         'if we have been exceeded retries on a previous error in this routine,
  968.         'just give the remaining errors one try, and don't save these errors,
  969.         'the interest should be in the original error
  970.         If Success = False Then
  971.             Resume Next
  972.         Else
  973.             'increment the retry counter
  974.             BadCount = BadCount + 1
  975.             'Look for Database errors and see if you can fix the error by reconnecting
  976.             If Err = 3146 or Err = 3075 then
  977.                 'Try Reconnecting to the database, then
  978.                 'keep executing the same line of code in a hope that retries will
  979.                 'be the solution to the problem.
  980.                 On Error GoTo BadDate_rangeDoubleYourQuotesConnect
  981.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  982.                 On Error goto 0
  983.             End If
  984.             Resume 0
  985.         End If
  986.     Else
  987.         'At MaxRetries, flag a failure in the routine
  988.         Success = False
  989.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  990.         'get a reason why the error occurred
  991.         ErrorCode = Err
  992.         objError.ErrorCode = Err
  993.         objError.FunctionName = "clsDate_range.DoubleYourQuotes"
  994.         If Err = 3146 then
  995.             objError.Message = "Date_range, DoubleYourQuotes " & vbcrlf & Errors(0) & " "
  996.             ErrorMessage = Errors(0)
  997.         Else
  998.             objError.Message = "Date_range, DoubleYourQuotes "
  999.             ErrorMessage = Error(Err)
  1000.         End If
  1001.         objError.SQL = ""
  1002.         objError.Display vbExclamation
  1003.         'reset the counter
  1004.         BadCount = 0
  1005.         'and try to execute the next line of code in the routine
  1006.         Resume Next
  1007.     End If
  1008.  
  1009. BadDate_rangeDoubleYourQuotesConnect:
  1010.     'You can put additional database reopening error checking here if necessary
  1011.     Resume Next
  1012.  
  1013.  
  1014. End Sub
  1015.  
  1016. '********************************************************************************************************
  1017. 'Title:     SearchandDouble
  1018. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1019. 'Purpose:   This Function will look for any single quotes in a string passed to it
  1020. '           and double them for SQL compatibility
  1021. 'Parameters:string to be modified
  1022. 'Return:    the modified string
  1023. '********************************************************************************************************
  1024. Private Function SearchandDouble(lsBuf As String) As String
  1025.  
  1026. Dim liStrLen As Integer
  1027. Dim liCurChar As Integer
  1028. Dim liQuotePos As Integer
  1029. Dim lsQuote As String
  1030. Dim lsOutBuf As String
  1031.  
  1032.     lsQuote = "'"
  1033.     liCurChar = 1
  1034.     lsOutBuf = ""
  1035.     
  1036.     
  1037.     liQuotePos = InStr(liCurChar, lsBuf, lsQuote)
  1038.     If liQuotePos = 0 Then
  1039.         lsOutBuf = lsBuf
  1040.     Else
  1041.         liStrLen = Len(lsBuf)
  1042.         Do While liQuotePos > 0
  1043.             lsOutBuf = lsOutBuf & Mid(lsBuf, liCurChar, liQuotePos - liCurChar + 1) & lsQuote
  1044.             liCurChar = liQuotePos + 1
  1045.             liQuotePos = InStr(liCurChar, lsBuf, lsQuote)
  1046.         Loop
  1047.         lsOutBuf = lsOutBuf & Mid(lsBuf, liCurChar, liStrLen)
  1048.     End If
  1049.  
  1050.     SearchandDouble = lsOutBuf
  1051.  
  1052. End Function
  1053.  
  1054. '********************************************************************************************************
  1055. 'Title:     SetDefaultDates
  1056. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1057. 'Purpose:   This routine puts default date or NULL into blank or invalid date fields
  1058. 'Parameters:None
  1059. 'Return:    Nothing
  1060. '********************************************************************************************************
  1061. Private Sub SetDefaultDates()
  1062.  
  1063. Dim liCount as integer,BadCount as integer
  1064.  
  1065.     If Not objConfiguration.DebugFlag Then
  1066.         On Error GoTo NoDate_rangeSetDefaultDates
  1067.     End If
  1068.  
  1069.     'These lines look at the dates in the class, and put a NULL or your default date
  1070.      'depending on your data mode, when the date is
  1071.     'blank or invalid, since this is what sql expects
  1072.     if not isDate(Starting_Date) then
  1073.         Starting_Date = "NULL"
  1074.     Else
  1075.         Starting_Date = "#" & format(CDate(Starting_Date),"MM/DD/YYYY HH:MM:SS") & "#"
  1076.     Endif
  1077.     if not isDate(Ending_Date) then
  1078.         Ending_Date = "NULL"
  1079.     Else
  1080.         Ending_Date = "#" & format(CDate(Ending_Date),"MM/DD/YYYY HH:MM:SS") & "#"
  1081.     Endif
  1082.     if not isDate(Update_Time) then
  1083.         Update_Time = "NULL"
  1084.     Else
  1085.         Update_Time = "#" & format(CDate(Update_Time),"MM/DD/YYYY HH:MM:SS") & "#"
  1086.     Endif
  1087.     On Error GoTo 0
  1088.     Exit Sub
  1089.  
  1090. NoDate_rangeSetDefaultDates:
  1091.  
  1092.     'Retry for a predermined number of times, set by the MaxRetries Constant
  1093.     If BadCount < MaxRetries Then
  1094.         'if we have been exceeded retries on a previous error in this routine,
  1095.         'just give the remaining errors one try, and don't save these errors,
  1096.         'the interest should be in the original error
  1097.         If Success = False Then
  1098.             Resume Next
  1099.         Else
  1100.             'increment the retry counter
  1101.             BadCount = BadCount + 1
  1102.             'Look for Database errors and see if you can fix the error by reconnecting
  1103.             If Err = 3146 or Err = 3075 then
  1104.                 'Try Reconnecting to the database, then
  1105.                 'keep executing the same line of code in a hope that retries will
  1106.                 'be the solution to the problem.
  1107.                 On Error GoTo BadDate_rangeSetDefaultDatesConnect
  1108.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  1109.                 On Error goto 0
  1110.             End If
  1111.             Resume 0
  1112.         End If
  1113.     Else
  1114.         'At MaxRetries, flag a failure in the routine
  1115.         Success = False
  1116.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  1117.         'get a reason why the error occurred
  1118.         ErrorCode = Err
  1119.         objError.ErrorCode = Err
  1120.         objError.FunctionName = "clsDate_range.SetDefaultDates"
  1121.         If Err = 3146 then
  1122.             objError.Message = "Date_range, SetDefaultDates " & vbcrlf & Errors(0) & " "
  1123.             ErrorMessage = Errors(0)
  1124.         Else
  1125.             objError.Message = "Date_range, SetDefaultDates "
  1126.             ErrorMessage = Error(Err)
  1127.         End If
  1128.         objError.SQL = ""
  1129.         objError.Display vbExclamation
  1130.         'reset the counter
  1131.         BadCount = 0
  1132.         'and try to execute the next line of code in the routine
  1133.         Resume Next
  1134.     End If
  1135.  
  1136. BadDate_rangeSetDefaultDatesConnect:
  1137.     'You can put additional database reopening error checking here if necessary
  1138.     Resume Next
  1139.  
  1140.  
  1141. End Sub
  1142.  
  1143. '********************************************************************************************************
  1144. 'Title:     StripDates
  1145. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1146. 'Purpose:   This routine strips NULLS and bad Dates from Fields in the class, the delimiter field
  1147. '           determines whether it should check for the presence of Date Delimiters
  1148. 'Parameters:None
  1149. 'Return:    Nothing
  1150. '********************************************************************************************************
  1151. Private Sub StripDates(DelimiterFlag as integer)
  1152.  
  1153. Dim liCount as integer,BadCount as integer
  1154.  
  1155.     If Not objConfiguration.DebugFlag Then
  1156.         On Error GoTo NoDate_rangeStripDates
  1157.     End If
  1158.  
  1159.     'These lines check to see if a NULL has been entered into the field from the
  1160.     'DefaultDate subroutine, if it has, it is set to an empty string, the date from
  1161.     'the database is also checked, if it is invalid, it to is set to an empty string
  1162.     if Starting_Date = "NULL" then
  1163.         Starting_Date = ""
  1164.     Endif
  1165.     if Ending_Date = "NULL" then
  1166.         Ending_Date = ""
  1167.     Endif
  1168.     if Update_Time = "NULL" then
  1169.         Update_Time = ""
  1170.     Endif
  1171.     On Error GoTo 0
  1172.     Exit Sub
  1173.  
  1174. NoDate_rangeStripDates:
  1175.  
  1176.     'Retry for a predermined number of times, set by the MaxRetries Constant
  1177.     If BadCount < MaxRetries Then
  1178.         'if we have been exceeded retries on a previous error in this routine,
  1179.         'just give the remaining errors one try, and don't save these errors,
  1180.         'the interest should be in the original error
  1181.         If Success = False Then
  1182.             Resume Next
  1183.         Else
  1184.             'increment the retry counter
  1185.             BadCount = BadCount + 1
  1186.             'Look for Database errors and see if you can fix the error by reconnecting
  1187.             If Err = 3146 or Err = 3075 then
  1188.                 'Try Reconnecting to the database, then
  1189.                 'keep executing the same line of code in a hope that retries will
  1190.                 'be the solution to the problem.
  1191.                 On Error GoTo BadDate_rangeStripDatesConnect
  1192.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  1193.                 On Error goto 0
  1194.             End If
  1195.             Resume 0
  1196.         End If
  1197.     Else
  1198.         'At MaxRetries, flag a failure in the routine
  1199.         Success = False
  1200.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  1201.         'get a reason why the error occurred
  1202.         ErrorCode = Err
  1203.         objError.ErrorCode = Err
  1204.         objError.FunctionName = "clsDate_range.StripDates"
  1205.         If Err = 3146 then
  1206.             objError.Message = "Date_range, StripDates " & vbcrlf & Errors(0) & " "
  1207.             ErrorMessage = Errors(0)
  1208.         Else
  1209.             objError.Message = "Date_range, StripDates "
  1210.             ErrorMessage = Error(Err)
  1211.         End If
  1212.         objError.SQL = ""
  1213.         objError.Display vbExclamation
  1214.         'reset the counter
  1215.         BadCount = 0
  1216.         'and try to execute the next line of code in the routine
  1217.         Resume Next
  1218.     End If
  1219.  
  1220. BadDate_rangeStripDatesConnect:
  1221.     'You can put additional database reopening error checking here if necessary
  1222.     Resume Next
  1223.  
  1224.  
  1225. End Sub
  1226.  
  1227. '********************************************************************************************************
  1228. 'Title:     PadFields
  1229. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1230. 'Purpose:   This routine Pads any fields with a space which do not allow zero length
  1231. 'Purpose:   The Allow zero length property is set by default in Access databases and is
  1232. '           used also in Oracle and SQLServer if the if fields are not padded with space
  1233. '           the database won't add the record, sometimes this is desirable sometimes not
  1234. 'Parameters:None
  1235. 'Return:    Nothing
  1236. '********************************************************************************************************
  1237. Private Sub PadFields()
  1238.  
  1239. Dim liCount as integer,BadCount as integer
  1240.  
  1241.     If Not objConfiguration.DebugFlag Then
  1242.         On Error GoTo NoDate_rangePadFields
  1243.     End If
  1244.  
  1245.     'These lines put a space into any field which does not allow zero length, so the
  1246.     'record can be added anyway
  1247.     if Trim(Updated_By) = "" then
  1248.             Updated_By = " "
  1249.     Endif
  1250.     if Trim(Update_Module) = "" then
  1251.             Update_Module = " "
  1252.     Endif
  1253.     On Error GoTo 0
  1254.     Exit Sub
  1255.  
  1256. NoDate_rangePadFields:
  1257.  
  1258.     'Retry for a predermined number of times, set by the MaxRetries Constant
  1259.     If BadCount < MaxRetries Then
  1260.         'if we have been exceeded retries on a previous error in this routine,
  1261.         'just give the remaining errors one try, and don't save these errors,
  1262.         'the interest should be in the original error
  1263.         If Success = False Then
  1264.             Resume Next
  1265.         Else
  1266.             'increment the retry counter
  1267.             BadCount = BadCount + 1
  1268.             'Look for Database errors and see if you can fix the error by reconnecting
  1269.             If Err = 3146 or Err = 3075 then
  1270.                 'Try Reconnecting to the database, then
  1271.                 'keep executing the same line of code in a hope that retries will
  1272.                 'be the solution to the problem.
  1273.                 On Error GoTo BadDate_rangePadFieldsConnect
  1274.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  1275.                 On Error goto 0
  1276.             End If
  1277.             Resume 0
  1278.         End If
  1279.     Else
  1280.         'At MaxRetries, flag a failure in the routine
  1281.         Success = False
  1282.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  1283.         'get a reason why the error occurred
  1284.         ErrorCode = Err
  1285.         objError.ErrorCode = Err
  1286.         objError.FunctionName = "clsDate_range.PadFields"
  1287.         If Err = 3146 then
  1288.             objError.Message = "Date_range, PadFields " & vbcrlf & Errors(0) & " "
  1289.             ErrorMessage = Errors(0)
  1290.         Else
  1291.             objError.Message = "Date_range, PadFields "
  1292.             ErrorMessage = Error(Err)
  1293.         End If
  1294.         objError.SQL = ""
  1295.         objError.Display vbExclamation
  1296.         'reset the counter
  1297.         BadCount = 0
  1298.         'and try to execute the next line of code in the routine
  1299.         Resume Next
  1300.     End If
  1301.  
  1302. BadDate_rangePadFieldsConnect:
  1303.     'You can put additional database reopening error checking here if necessary
  1304.     Resume Next
  1305.  
  1306.  
  1307. End Sub
  1308.  
  1309. '********************************************************************************************************
  1310. 'Title:     TrimPaddedFields
  1311. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1312. 'Purpose:   This routine Trims the fields which have spaces at beginning or end
  1313. 'Parameters:None
  1314. 'Return:    Nothing
  1315. '********************************************************************************************************
  1316. Private Sub TrimPaddedFields()
  1317.  
  1318. Dim liCount as integer,BadCount as integer
  1319.  
  1320.     If Not objConfiguration.DebugFlag Then
  1321.         On Error GoTo NoDate_rangeTrimPaddedFields
  1322.     End If
  1323.  
  1324.     'This routine deletes the spaces from any padded fields
  1325.     Updated_By = Trim(Updated_By)
  1326.     Update_Module = Trim(Update_Module)
  1327.     On Error GoTo 0
  1328.     Exit Sub
  1329.  
  1330. NoDate_rangeTrimPaddedFields:
  1331.  
  1332.     'Retry for a predermined number of times, set by the MaxRetries Constant
  1333.     If BadCount < MaxRetries Then
  1334.         'if we have been exceeded retries on a previous error in this routine,
  1335.         'just give the remaining errors one try, and don't save these errors,
  1336.         'the interest should be in the original error
  1337.         If Success = False Then
  1338.             Resume Next
  1339.         Else
  1340.             'increment the retry counter
  1341.             BadCount = BadCount + 1
  1342.             'Look for Database errors and see if you can fix the error by reconnecting
  1343.             If Err = 3146 or Err = 3075 then
  1344.                 'Try Reconnecting to the database, then
  1345.                 'keep executing the same line of code in a hope that retries will
  1346.                 'be the solution to the problem.
  1347.                 On Error GoTo BadDate_rangeTrimPaddedFieldsConnect
  1348.                 Set Dbtimesheet = OpenDatabase(Objconfiguration.datasource)
  1349.                 On Error goto 0
  1350.             End If
  1351.             Resume 0
  1352.         End If
  1353.     Else
  1354.         'At MaxRetries, flag a failure in the routine
  1355.         Success = False
  1356.         'set the ErrorCode and ErrorMessage Properties so the programmer can
  1357.         'get a reason why the error occurred
  1358.         ErrorCode = Err
  1359.         objError.ErrorCode = Err
  1360.         objError.FunctionName = "clsDate_range.TrimPaddedFields"
  1361.         If Err = 3146 then
  1362.             objError.Message = "Date_range, TrimPaddedFields " & vbcrlf & Errors(0) & " "
  1363.             ErrorMessage = Errors(0)
  1364.         Else
  1365.             objError.Message = "Date_range, TrimPaddedFields "
  1366.             ErrorMessage = Error(Err)
  1367.         End If
  1368.         objError.SQL = ""
  1369.         objError.Display vbExclamation
  1370.         'reset the counter
  1371.         BadCount = 0
  1372.         'and try to execute the next line of code in the routine
  1373.         Resume Next
  1374.     End If
  1375.  
  1376. BadDate_rangeTrimPaddedFieldsConnect:
  1377.     'You can put additional database reopening error checking here if necessary
  1378.     Resume Next
  1379.  
  1380.  
  1381. End Sub
  1382.  
  1383.  
  1384. '********************************************************************************************************
  1385. 'Title:     StoreProperties
  1386. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1387. 'Purpose    This Sub Assigns the Properties of the Class to the
  1388. '           private class scratchpad variables
  1389. 'Parameters:None
  1390. 'Return:    Nothing
  1391. '********************************************************************************************************
  1392. Private Sub StoreProperties()
  1393.  
  1394.     mDate_Id = Date_Id
  1395.     mStarting_Date = Starting_Date
  1396.     mEnding_Date = Ending_Date
  1397.     mUpdated_By = Updated_By
  1398.     mUpdate_Module = Update_Module
  1399.     mUpdate_Time = Update_Time
  1400.  
  1401. End Sub
  1402.  
  1403. '********************************************************************************************************
  1404. 'Title:     RetrieveProperties
  1405. 'Author:    DesignGrid by W. David Ewing, Copyright 1998
  1406. 'Purpose    This Sub Assigns the ScratchPad Variable Values back to the Class properties
  1407. 'Parameters:None
  1408. 'Return:    Nothing
  1409. '********************************************************************************************************
  1410. Private Sub RetrieveProperties()
  1411.  
  1412.     Date_Id = mDate_Id
  1413.     Starting_Date = mStarting_Date
  1414.     Ending_Date = mEnding_Date
  1415.     Updated_By = mUpdated_By
  1416.     Update_Module = mUpdate_Module
  1417.     Update_Time = mUpdate_Time
  1418.  
  1419. End Sub
  1420.